using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace Ricciolo.PaperBoy.UI
{
    /// <summary>
    /// Interaction logic for FeedIcon.xaml
    /// </summary>
    public partial class FeedIcon : System.Windows.Controls.Canvas
    {

        public static DependencyProperty IsRefreshingProperty = DependencyProperty.Register("IsRefreshing", typeof(Boolean), typeof(FeedIcon), new PropertyMetadata(new PropertyChangedCallback(OnIsRefreshingChanged)));

        static FeedIcon()
        {
        }

        public FeedIcon()
        {
            InitializeComponent();
        }

        protected static void OnIsRefreshingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FeedIcon f = (FeedIcon)d;
            Storyboard anim = (Storyboard)f.FindResource("animation");
            if (anim != null)
            {
                if (f.IsRefreshing)
                {
                    anim.Begin(f, true);
                    //f.BeginStoryboard(anim);
                }
                else
                    anim.Stop(f);
            }
        }

        public bool IsRefreshing
        {
            get { return (Boolean)this.GetValue(IsRefreshingProperty); }
            set { this.SetValue(IsRefreshingProperty, value); }
        }
    }
}